<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <script>
        function foo(){
            console.log("1")
        }
    </script>

</head>
<body>
    <!-- 行内脚本 -->
    <button onclick="foo()">点击按钮</button>

    <!-- <button onclick='console.log("1")'>点击按钮</button> -->

    <script>
        // 事件绑定(覆盖之前的事件)
        document.querySelectorAll("button")[0].onclick = function(){
            console.log("2");
        }

        document.querySelectorAll("button")[0].addEventListener("click",function(){
            console.log("test 1");
        })
        document.querySelectorAll("button")[0].addEventListener("click",function(){
            console.log("test 2");
        })

    </script>
</body>
</html>